###############################################
# XENOMORPH ON ACTIONS — CONSOLIDATED
# Put in: common/on_actions/xenomorph_on_actions.txt
#
# Consolidated from xenomorph_on_actions.txt + xenomorph_building_lockout_on_actions.txt.
# Duplicate event calls and duplicate on_action declarations removed.
#
# Deprecated: xenomorph_queen_mother_capital.1 is not included; use
# xenomorph_queen_mother_start.1 instead.
###############################################

#############################################
# GAME START HOOKS
#############################################

# Fires once at game start.
# xenogeneral.1 spawns the Xenomorph Prime system.
# xenogeneral.4 sets up the Queen Mother origin capital.
# xenogeneral.6 sets up the Xenomorph Prime origin capital.
# Fires once per country at game start. ALL Xeno startup events use this hook
# (they all use country-scope effects: ruler, capital_scope, random_rim_system).
# xenogeneral.1 spawns the Xenomorph Prime system (one per Xeno empire that exists at game start).
# xenogeneral.4 sets up Queen Mother origin capital flavour (5 pops + flag).
# xenogeneral.6 sets up Xenomorph Prime origin capital.
# xenomorph_start.1/.2 swap vanilla starting infrastructure into Xenomorph replacements.
# xenomorph_queen_mother_start.1 performs Queen Mother capital building setup.
# xeno_lv_compat.1 detects Lustful Void at game start.
on_game_start_country = {
	events = {
		xeno_lv_compat.100  # 3_66 LV-compat wiring
		xenogeneral.1
		xenogeneral.4
		xenogeneral.6
		xenomorph_start.1
		xenomorph_start.2
		xenomorph_queen_mother_start.1
		xenomorph_lab_escape_start.1
		xenomorph_crashed_derelict_start.1
		xenomorph_scattered_brood_start.1
		xeno_captor_start.1
		xeno_captor_start.2
		xeno_qcaptive.900
		xeno_lv_compat.1
	}
}

#############################################
# GENERAL COLONY / COUNTRY PULSES
#############################################

# Fires once per country when the player presses Begin, after empire/species
# setup. Country scope. FIX 2026-07: this is the hook MGHG_game_start.28 uses
# to create secondary-species pops (the designer secondary species is reliably
# owned here, unlike at on_game_start_country). Used by Laboratory Escapees.
# Fires during empire initialization for origins with has_secondary_species.
# Scope = planet (capital); last_created_species = the designer secondary species.
# FIX 2026-07 (revised): was on_press_begin + random_owned_species, which only
# finds a species that already has owned pops. For a hive-mind main species the
# non-hive host secondary may have zero starting pops, so random_owned_species
# found nothing and no host pops spawned. This is LV's proven pattern for
# has_secondary_species origins (lv_game_start.3).
empire_init_capital_planet = {
	events = {
		xenomorph_lab_escape_start.2
	}
}

# Fires yearly on colonies.
# xenocivic.1 is gated inside the event trigger to Xenomorph empires only.
on_colony_yearly_pulse = {
	events = {
		xenocivic.1
	}
}

# Fires when a planet is colonized. Scope = Planet.
# FIX 2026-07: was hooked to "on_colony_established", which is NOT a vanilla
# on_action (vanilla hook is on_colonized; confirmed against LV and MGHG
# on_action files). The colony-setup chain never fired on new colonies.
# xenomorph_start.4 bridges planet scope -> xenomorph_start.3 (capital swap).
# xenogeneral.5 flags Xenomorph planets so localisation/building systems can display Xenomorph-themed names.
on_colonized = {
	events = {
		xenomorph_start.4
	}
}

# Monthly pulse.
# xenomorph_start.2 = continuous vanilla building lockout (catches new vanilla buildings added by events/mods).
# xeno_hostline.1 = monthly hostline milestone checks for Xenomorph hive countries.
on_monthly_pulse_country = {
	events = {
		xenomorph_start.2
		xeno_hostline.1
		xeno_captive.90
	}
}

# Yearly pulse.
# xeno_queen_mother.10 = Queen Mother yearly maintenance.
# xeno_hive_world.10 = Xenomorph Hive World yearly maintenance (applies owner-specific modifiers).
# xeno_hive_world.20 = Optional origin-start hook for origins that should begin on pc_xenomorph_hive.
on_yearly_pulse_country = {
	events = {
		xeno_queen_mother.10
		xeno_hive_world.10
		xeno_hive_world.20
		xeno_lv_compat.10
		xeno_lv_compat.30
	}
}

#############################################
# NECROPHAGE / PURGE CONVERSION
#############################################

# Pop purge conversion hook for rapid Xenomorph necrophage processing.
# on_pop_purged scope:
#   THIS             = planet scope
#   FROM             = country, the purger / planet owner
#   FROMFROM         = pop group that was purged
#   local_pop_amount = number of pops purged in this tick
on_pop_purged = {
	events = {
		xeno_necrophage.1
	}
}

#############################################
# RAID / PLANET PICTURE HOOKS
#############################################

# Triggers country_event for the attacker upon victory, before controller is switched.
# This = country, lead attacker
# From = country, planet owner
# FromFrom = planet
on_planet_attackers_win = {
	events = {
		xeno_pic_events.28
		xeno_capture.1
	}
}

# Space capture hook (Flesh Harvest / Void Reavers): chance to recover a leader
# from a destroyed enemy fleet. ROOT = victor, FROM = destroyed fleet.
on_fleet_destroyed_perp = {
	events = {
		xeno_capture.2
		xeno_captor.300
	}
}

# Triggers country_event for the defender upon victory.
# This = country, planet owner
# From = country, attack leader
# FromFrom = planet
on_planet_defenders_win = {
	events = {
		xeno_pic_events.29
	}
}

# Fired whenever a new owner is set for a planet, following a war or through trade.
# This = planet
# From = country, new owner
# FromFrom = country, previous owner if any
on_planet_transfer = {
	events = {
		xeno_pic_events.25
	}
}

#############################################
# LEADER / BRANCH OFFICE HOOKS
#############################################

# External compatibility hook for systems that emit on_leader_captured.
on_leader_captured = {
	events = {
		xeno_pic_events.31
	}
}

# Captive death hook: fires a flavor event if the dying leader was a captive.
# Also checks for Queen Mother death (xeno_queen_mother.200 -> succession crisis).
on_leader_death = {
	events = {
		xeno_queen_mother.200
	}
}

# First-contact hook: Xeno-flavoured greeting (the hive sizes up new host-stock).
on_first_contact = {
	events = {
		xeno_meet.1
	}
}

# Branch office / Swarm Hold establishment hook.
on_branch_office_established = {
	events = {
		xeno_pic_events.23
	}
}

# Pass 15: Yearly Host Stock auto-necrophage.
on_yearly_pulse_planet = {
	events = {
		xenocivic.2
	}
}

# 3_61 D2: monthly deficit starters for custom resources.
on_monthly_pulse_country = {
	events = {
		xeno_deficit.10
		xeno_deficit.11
	}
}
